package com.med.meddataintegrator.jwt.controller;


import com.med.meddataintegrator.common.basic.response.JsonResult;
import com.med.meddataintegrator.jwt.pojo.dto.LoginUserParams;
import com.med.meddataintegrator.jwt.pojo.dto.PatientRegisterParams;
import com.med.meddataintegrator.jwt.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@Slf4j
public class userController {

    @Autowired
    private UserService userService;


    /**
     * 此处的接口只是为了  测试 具体的验证逻辑 已经在在过滤器链中被捕获 交给了 sercurity框架区校验了
     * @param loginUserParams
     * @return
     */
    @PostMapping("/login")
    public String login(@RequestBody LoginUserParams loginUserParams){
        System.out.println(loginUserParams);
        return "login";
    }


    @PostMapping("/logout")
    public String logout(){
        return "logout";
    }


    /**
     * 注册:
     *  默认是患者注册
     * @param patientRegisterParams
     * @return
     */
    @PostMapping("/register")
    public JsonResult register(@Validated @RequestBody PatientRegisterParams patientRegisterParams){
        log.info("patientRegisterParams:{}",patientRegisterParams);
        return userService.register(patientRegisterParams);
    }


}
